home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / yk211src.lha / Yak_2.11_Src / handlers.c < prev    next >
C/C++ Source or Header  |  1995-11-05  |  32KB  |  1,055 lines

  1. /*
  2.  * Handlers.c
  3.  *
  4.  * This module contains the input handlers set up by Yak.
  5.  * 
  6.  * The main handler is for autopointing, keyactivation, keyclicking and blanking
  7.  * There's are 3 specialized handlers for mouse cycling functions : WindowToFront,
  8.  * WindowToBack, and ScreenCycling.
  9.  * 
  10.  */
  11.  
  12. #define __USE_SYSBASE
  13.  
  14. #include <exec/types.h>
  15. #include <exec/exec.h>
  16. #include <devices/console.h>
  17. #include <devices/input.h>
  18. #include <devices/inputevent.h>
  19. #include <libraries/commodities.h>
  20. #include <graphics/gfx.h>
  21. #include <graphics/gfxbase.h>
  22. #include <graphics/gfxmacros.h>
  23. #include <graphics/displayinfo.h>
  24. #include <hardware/custom.h>
  25. #include <hardware/dmabits.h>
  26. #include <intuition/intuition.h>
  27. #include <intuition/intuitionbase.h>
  28. #include <proto/exec.h>
  29. #include <proto/dos.h>
  30. #include <proto/layers.h>
  31. #include <proto/graphics.h>
  32. #include <proto/intuition.h>
  33. #include <proto/commodities.h>
  34. #include <ctype.h>
  35. #include <string.h>
  36. #include <stdio.h>
  37.  
  38. #include "code.h"
  39. #include "yak.h"
  40. #include "Settings.h"
  41. #include "Handlers.h"
  42. #include "hotkey_types.h"
  43. #ifdef PREFS
  44. #  define CATCOMP_NUMBERS
  45. #  include "yak_locale_strings.h"
  46. #  include "Requesters.h"
  47. #else
  48. #  ifndef CONV
  49. #    include "Beep.h"
  50. #    include "LastActiveWindow.h"
  51. #    include "CapShift.h"
  52. #  endif
  53. #endif
  54.  
  55.  
  56. static char ExcludeWbWindowPattern[20]; /* Normally it takes 13 bytes */
  57.  
  58.  
  59. YakHandler MouseCyclingHandlers[NUM_HANDLERS] = {
  60.    { NULL, NULL, 0, 0, 0, 0, NULL, "", NULL},
  61.    { NULL, NULL, 0, 0, 0, 0, NULL, "", NULL},
  62.    { NULL, NULL, 0, 0, 0, 0, NULL, "", NULL}
  63. };
  64.  
  65. YakHandler DEF_MOUSECYCLING[NUM_HANDLERS]= {
  66.    { NULL, WindowToFrontHandler, YKHK_INACTIVE, WINDOW_TOFRONT_EVENT, DEF_TOFRONT_CLICKS      , DEF_TOFRONT_OPTIONS      , DEF_TOFRONT_HOTKEY      , DEF_SCREENPATTERN },
  67.    { NULL, WindowToBackHandler , YKHK_INACTIVE, WINDOW_TOBACK_EVENT,  DEF_TOBACK_CLICKS       , DEF_TOBACK_OPTIONS       , DEF_TOBACK_HOTKEY       , DEF_SCREENPATTERN },
  68.    { NULL, ScreenCyclingHandler, YKHK_INACTIVE, SCREENCYCLING_EVENT,  DEF_SCREENCYCLING_CLICKS, DEF_SCREENCYCLING_OPTIONS, DEF_SCREENCYCLING_HOTKEY, DEF_SCREENPATTERN }
  69. };
  70.  
  71.  
  72. VOID
  73. CleanMouseCycling(void)
  74. {
  75.     register int i;
  76.     
  77.     for (i=0; i<NUM_HANDLERS; i++)
  78.     {
  79.         if (MouseCyclingHandlers[i].ScreenPatternData.pat)
  80.         { 
  81.             FreeVec(MouseCyclingHandlers[i].ScreenPatternData.pat);
  82.             MouseCyclingHandlers[i].ScreenPatternData.pat=NULL;
  83.         }
  84.  
  85.         if (MouseCyclingHandlers[i].KeyDef)
  86.         { 
  87.             FreeVec(MouseCyclingHandlers[i].KeyDef);
  88.             MouseCyclingHandlers[i].KeyDef=NULL;
  89.         }
  90.  
  91.         /* DeleteCxObjAll() works even with NULL argument */
  92.         DeleteCxObjAll(MouseCyclingHandlers[i].CxObj);    
  93.         MouseCyclingHandlers[i].CxObj=NULL;
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. VOID
  100. InitMouseCyclingPatterns (VOID)
  101. {
  102.     UBYTE i;
  103.  
  104.     for (i=0; i<NUM_HANDLERS; i++)
  105.     {
  106.         InitPattern(MouseCyclingHandlers[i].ScreenPatternData.patstr,
  107.                     &MouseCyclingHandlers[i].ScreenPatternData);
  108.     }
  109.  
  110. #if !defined(PREFS) && !defined(CONV)
  111.     /* Initialize the pattern to exclude Wb window for Window_To_Front */
  112.     ParsePattern("~(Workbench)", ExcludeWbWindowPattern, 20);
  113. #endif    
  114. }
  115.  
  116.  
  117. /*
  118.  *  CompatibleParseIX - frontend to ParseIX() to allow compatibility of V38+ 
  119.  *  commodity.library hotkey definitions with V37 library.
  120.  */
  121.  
  122. long 
  123. CompatibleParseIX(char *I_Description, IX *ix)
  124. {
  125.     char *pos=NULL;
  126.     UBYTE c, begin;
  127.     long failurecode = 0l;
  128.     UWORD code = 0;
  129.     char *description;
  130.  
  131.         if (I_Description == NULL)
  132.         {
  133.                 failurecode = -2;
  134.         }
  135.         else
  136.         {
  137.                 /* Skip blank spaces in a 68000 compatible way, avoid odd addresses */
  138.  
  139.                 begin = 0;
  140.                 while (I_Description[begin] == ' ') 
  141.                 {
  142.                         begin++;
  143.                 }
  144.  
  145.                 if (CxBase->lib_Version < 38L) /* COMMODITIES_V37 */
  146.                 {
  147.                         description = AllocVec(strlen(I_Description)+1-begin, MEMF_CLEAR);
  148.  
  149.                         for (c=begin; c<strlen(I_Description); c++)
  150.                                 description[c-begin] = tolower(I_Description[c]);
  151.  
  152.                         /*
  153.                          *  parse and remove keywords that are not supported
  154.                          *  by V37 commodities.library
  155.                          *
  156.                          */
  157.                         if (pos = strstr(description, " mouse_leftpress"))
  158.                         {
  159.                                 code = IECODE_LBUTTON;
  160.                         }
  161.                         else 
  162.                         {
  163.                                 if (pos = strstr(description, " mouse_rightpress"))
  164.                                 {
  165.                                         code = IECODE_RBUTTON;
  166.                                 }
  167.                                 else 
  168.                                 {
  169.                                         if (pos = strstr(description, " mouse_middlepress"))
  170.                                         {
  171.                                                 code = IECODE_MBUTTON;
  172.                                         }
  173.                                 }
  174.                         }
  175.  
  176.                         if (pos)                        /* RawMouse class */
  177.                         {
  178.                                 /* Put an end to our description before unsupported keywords
  179.                                  * but avoid odd address for 68000 
  180.                                  */
  181.                                 description[(LONG)pos - (LONG)description]= '\0';
  182.                         }
  183.  
  184.                         failurecode = ParseIX((UBYTE *)description, ix);
  185.  
  186.                         /*
  187.                          *  now change ix for our new keywords
  188.                          *
  189.                          */
  190.                         if (code) 
  191.                         {
  192.                                 /*
  193.                                  *  change code
  194.                                  *
  195.                                  */
  196.                                 if (ix->ix_Class != IECLASS_RAWMOUSE)
  197.                                         failurecode = -1;
  198.                                 else
  199.                                         ix->ix_Code = code;
  200.             
  201.                                 /*
  202.                                  *  change also QualMask for mouse buttons
  203.                                  *
  204.                                  */
  205.                                 ix->ix_QualMask |= IEQUALIFIER_MIDBUTTON | IEQUALIFIER_RBUTTON | IEQUALIFIER_LEFTBUTTON;
  206.  
  207.                                 /*
  208.                                  *  parse for qualifiers the use wants to be considered irrelevant
  209.                                  *
  210.                                  */
  211.                                 if (strstr(description, "-leftbutton")) ix->ix_QualMask &= ~IEQUALIFIER_LEFTBUTTON;
  212.                                 if (strstr(description, "-midbutton")) ix->ix_QualMask &= ~IEQUALIFIER_MIDBUTTON;
  213.                                 if (strstr(description, "-rbutton")) ix->ix_QualMask &= ~IEQUALIFIER_RBUTTON;
  214.  
  215.                         }
  216.  
  217.                         FreeVec(description);
  218.                 }
  219.                 else                                    /* COMMODITIES_V38+ */
  220.                 {
  221.                         /* Use the definition as is */
  222.                         failurecode = ParseIX((UBYTE *)I_Description, ix);
  223.                 }
  224.  
  225.                 if (!failurecode)
  226.                 {
  227.                         /* Patch ParseIX() up */
  228.                         if (ix->ix_Class == IECLASS_RAWMOUSE)
  229.                         {
  230.                                 if (ix->ix_Code == IECODE_LBUTTON) ix->ix_Qualifier |= IEQUALIFIER_LEFTBUTTON;
  231.                                 if (ix->ix_Code == IECODE_MBUTTON) ix->ix_Qualifier |= IEQUALIFIER_MIDBUTTON;
  232.                                 if (ix->ix_Code == IECODE_RBUTTON) ix->ix_Qualifier |= IEQUALIFIER_RBUTTON;
  233.                         }
  234.                         ix->ix_QualMask |= ix->ix_Qualifier;
  235.                 }
  236.         }
  237.     return(failurecode);
  238. }
  239.  
  240. #if !defined(PREFS) && !defined(CONV)
  241.  
  242. void TurnMouseOn (void);
  243. static void TurnMouseOff (void);
  244. static __regargs void IntuiOp (void (*routine) (APTR), APTR parameter);
  245. static __regargs void PopToFront (struct Window *win);
  246. static __regargs BOOL StrGadgetActive (struct Window *w);
  247.  
  248. extern __far struct Custom custom;
  249.  
  250. #define REBLANKCOUNT    10      /* how long to wait to reblank mouse */
  251. #define TURN_OFF_SPRITES {OFF_SPRITE;custom.spr[0].dataa = custom.spr[0].datab = 0;}
  252.  
  253. void (*intui_routine) (APTR);   /* for intui_op's */
  254. APTR intui_parameter;
  255. CxObj *clickobj;
  256. ULONG clicksigflag, intuiopsigflag, blankscreensigflag, depthscreensigflag;
  257. static BYTE clicksigbit, blankscreensigbit, depthscreensigbit, intuiopsigbit = -1;
  258. static BOOL misspop;
  259.  
  260. /* for screen cycling */
  261. STACKARGS void
  262. MyScreenToBack (struct Screen *scr)
  263. {
  264.   RememberActiveWindow(NULL);
  265.   ScreenToBack (scr);
  266.   ActivateMouseWindow (SCREEN);
  267. }
  268.  
  269. STACKARGS void
  270. MyScreenToFront (struct Screen *scr)
  271. {
  272.   RememberActiveWindow(NULL);
  273.   ScreenToFront (scr);
  274.   ActivateMouseWindow (SCREEN);
  275. }
  276.  
  277.  
  278. /* Stub for Intuition routines - passes request on to main task.
  279.  * DO NOT CALL WHILE FORBID()ING!
  280.  * Thanks to Eddy Carroll for this.
  281.  */
  282.  
  283. #define WTB(win)        IntuiOp(WindowToBack, win)
  284. #define WTF(win)        IntuiOp(WindowToFront, win)
  285. #define WACT(win)       IntuiOp((void (*)(APTR))ActivateWindow, win)
  286. #define STB(scr)        IntuiOp(MyScreenToBack, scr)
  287. #define STF(scr)        IntuiOp(MyScreenToFront, scr)
  288.  
  289. BYTE oldpri;                  /* used by main.c */
  290. static struct Task *YakTask;  
  291.  
  292. static __regargs void
  293. IntuiOp (void (*routine) (APTR), APTR parameter)
  294. {
  295.   oldpri  = SetTaskPri (YakTask, 21);
  296.   intui_routine = routine;
  297.   intui_parameter = parameter;
  298.   Signal (YakTask, intuiopsigflag);
  299.   SetTaskPri (YakTask, oldpri);
  300. }
  301.  
  302. /* pattern-matching on screen/window titles */
  303. #define IsXXXScreen(scr, pat)          (scr && (!scr->DefaultTitle || MatchPattern(pat, scr->DefaultTitle)))
  304. #define IsAutoScreen(scr)              IsXXXScreen(scr, autoscrpat)
  305. #define IsXXXWindow(win, pat)          (!win->Title || MatchPattern(pat, win->Title))
  306. #define IsPopWindow(win)               IsXXXWindow(win,popwinpat)
  307. #define IsNotWbWindow(win)             (!win->Title || MatchPattern(ExcludeWbWindowPattern, win->Title))
  308. #define IsIncludedScreen(scr,handler)  IsXXXScreen(scr, handler.ScreenPatternData.pat) 
  309.  
  310. /* when is a window safe to bring to front and not already at front? */
  311. #define OkayToPop(win)  (!win->ReqCount && !(win->Flags & (WFLG_MENUSTATE|WFLG_BACKDROP)) \
  312.                          && win->WLayer->ClipRect && win->WLayer->ClipRect->Next)
  313.  
  314.  
  315.  
  316. /* WindowToFront only if no requester, not backdrop, not already front... */
  317. static __regargs void
  318. PopToFront (struct Window *win)
  319. {
  320.     /* want to avoid popping immediately after mousebutton/keyboard */
  321.     if (misspop)
  322.     {
  323.         misspop = FALSE;
  324.     }
  325.     else
  326.     { 
  327.         if (OkayToPop (win))
  328.         {
  329.             /* Does it pass pattern? */
  330.             if (IsPopWindow (win))
  331.             {
  332.                 WTF (win); /* We use signals to reduce time spent in the input device */
  333.             }
  334.         }
  335.     }
  336. }
  337.  
  338. /* modified from DMouse */
  339. /* expects multitasking to be Forbid()en */
  340.  
  341. static struct Screen *mousescr; /* the screen under the mouse */
  342.  
  343.  
  344. struct Screen *
  345. ScreenUnderMouse( void )
  346. {
  347.   struct Screen *scr;
  348.   ULONG lock;
  349.  
  350.   lock = LockIBase(0);
  351.         
  352.   for (scr = IntuitionBase->FirstScreen;
  353.            scr && scr->TopEdge > 0 && scr->MouseY < 0; 
  354.            scr = scr->NextScreen);
  355.  
  356.   UnlockIBase(lock);
  357.  
  358.   return(scr);
  359. }
  360.  
  361.  
  362. struct Window *
  363. WindowUnderMouse( void )
  364. {
  365.   struct Layer *layer = NULL;
  366.   ULONG lock;
  367.  
  368.   lock = LockIBase(0);
  369.         
  370.   for (mousescr = IntuitionBase->FirstScreen;
  371.            mousescr && mousescr->TopEdge > 0 && mousescr->MouseY < 0; 
  372.            mousescr = mousescr->NextScreen);
  373.  
  374.   UnlockIBase(lock);
  375.  
  376.   if (mousescr)
  377.           layer = WhichLayer(&mousescr->LayerInfo, mousescr->MouseX, mousescr->MouseY);
  378.       
  379.   return (layer ? (struct Window *) layer->Window : NULL);
  380. }
  381.  
  382.  
  383. /* does active window have an active string gadget? */
  384. static __regargs BOOL
  385. StrGadgetActive (struct Window *w)
  386. {
  387.   struct Gadget *g = w->FirstGadget;
  388.  
  389.   for (; g; g = g->NextGadget)
  390.     if ((g->GadgetType & STRGADGET) && (g->Flags & GFLG_SELECTED))
  391.       return TRUE;
  392.   return FALSE;
  393. }
  394.  
  395. /* activate window under mouse */
  396. /* context sensitive; why tells routine how to behave */
  397. /* can be AUTO, KEY, SCREEN, RMBACT */
  398. __regargs void
  399. ActivateMouseWindow (BYTE why)
  400. {
  401.     struct Window *win = NULL, *IB_ActiveWindow;
  402.     ULONG lock;
  403.  
  404.     if ((why != SCREEN) || scractivate)
  405.     {
  406.         if (why == SCREEN)
  407.                 {
  408.             win = LastActiveWindow(ScreenUnderMouse());
  409.                 }
  410.  
  411.         if (!win)
  412.             win = WindowUnderMouse ();
  413.  
  414.         if (win)                /* window exists to activate */
  415.         {
  416.             /* either window is not active or auto-activating - need to pop? */
  417.           
  418.             if (win->Flags & WFLG_WINDOWACTIVE) /* already active - needs popped? */
  419.             {
  420.                 if (why == AUTO && autopop && IsAutoScreen (win->WScreen))
  421.                 {
  422.                     PopToFront (win);
  423.                 }
  424.             }
  425.             else if (why != AUTO || IsAutoScreen (win->WScreen))
  426.             {
  427.                 /* window is not active, should we try to activate it? */
  428.                   
  429.                 lock = LockIBase(0);
  430.                 IB_ActiveWindow = IntuitionBase->ActiveWindow;
  431.                 UnlockIBase(lock);
  432.  
  433.                 if (!IB_ActiveWindow ||
  434.                     !(IB_ActiveWindow->Flags & WFLG_MENUSTATE) && /* not showing menus */
  435.                     !(why == KEY && StrGadgetActive (IB_ActiveWindow))) /* no str gad active */
  436.                 {
  437.                           
  438.                     /* do autopop? */
  439.                     if (why == AUTO && autopop)
  440.                         PopToFront (win);
  441.                           
  442.                     if (why == KEY)
  443.                         ActivateWindow (win); /* need this to avoid losing keys */
  444.                     else
  445.                         WACT (win); /* ...activate window */
  446.  
  447.                                         RememberActiveWindow(win);
  448.  
  449.                 }
  450.             }
  451.         }
  452.         else
  453.         {
  454.             lock = LockIBase(0);
  455.             IB_ActiveWindow = IntuitionBase->ActiveWindow; 
  456.             UnlockIBase(lock);
  457.  
  458.             if (scractivate && mousescr && mousescr->FirstWindow &&
  459.                 ((why == SCREEN) || 
  460.                  (why == RMBACT && IB_ActiveWindow && IB_ActiveWindow->WScreen != mousescr)))
  461.             {
  462.                 WACT (mousescr->FirstWindow); /* ...activate window */
  463.                                 RememberActiveWindow(mousescr->FirstWindow);
  464.             }
  465.         }
  466.     }
  467. }
  468.  
  469. static __chip UWORD posctldata[4];
  470. static struct SimpleSprite simplesprite =
  471. {posctldata, 0, 0, 0, 0};
  472. static BOOL mouseoff;           /* is mouse off? (MB_SPRITES only) */
  473.  
  474. void 
  475. TurnMouseOn ()                  /* restore mouse-pointer */
  476. {
  477.     if (mouseblank == MB_SPRITES) /* really dirty blanking */
  478.     {                           /* but guaranteed to work... */
  479.         if (mouseoff)
  480.         {
  481.             Forbid ();
  482.             WaitTOF ();
  483.             ON_SPRITE;
  484.             Permit ();
  485.         }
  486.     }
  487.     else
  488.     {
  489.         RethinkDisplay();
  490.     }
  491.     mouseoff = FALSE;
  492. }
  493.  
  494. static void 
  495. TurnMouseOff ()                 /* blank mouse-pointer */
  496. {
  497.     if (!mouseoff)              /* no point in turning it off twice... */
  498.     {
  499.         Forbid ();
  500.  
  501.         if (mouseblank == MB_SPRITES)
  502.         {
  503.             WaitTOF ();
  504.             OFF_SPRITE;
  505.             custom.spr[0].dataa = custom.spr[0].datab = 0;          
  506.         }
  507.         else
  508.         {
  509.             ChangeSprite(NULL, &simplesprite, (APTR)posctldata);
  510.         }
  511.  
  512.         Permit ();
  513.  
  514.         mouseoff = TRUE;
  515.     }
  516. }
  517.  
  518. BOOL blanked;
  519. static struct Screen *blankscr;
  520.  
  521. void
  522. BlankScreen ()
  523. {
  524.     if (screenblank == SB_DMA)
  525.     {
  526.         /* Turn DMA off */
  527.         custom.dmacon = BITCLR|DMAF_RASTER|DMAF_COPPER|DMAF_SPRITE;  
  528.  
  529.         blanked = TRUE;
  530.     }
  531.     else
  532.     {
  533.         ULONG modeid = INVALID_ID;
  534.         
  535.         if (blankscr)
  536.             ScreenToFront (blankscr);
  537.         else
  538.         {
  539.             Forbid ();
  540.             if (IntuitionBase->FirstScreen)
  541.                 modeid = GetVPModeID (&(IntuitionBase->FirstScreen->ViewPort));
  542.             Permit ();
  543.             if (modeid == INVALID_ID)
  544.                 modeid = LORES_KEY;
  545.                 
  546.             if (blankscr = OpenScreenTags (NULL, SA_Depth, 1,
  547.                                            SA_Title, "Yak blanking screen",
  548.                                            SA_Quiet, TRUE,
  549.                                            SA_Behind, TRUE,
  550.                                            SA_DisplayID, modeid,
  551.                                            TAG_DONE))
  552.             {
  553.                 SetRGB4 (&blankscr->ViewPort, 0, 0, 0, 0);
  554.                 ScreenToFront (blankscr);
  555.                 blanked = TRUE;
  556.             }
  557.         }
  558.         /* Blank all the sprites */
  559.         TURN_OFF_SPRITES; 
  560.     }
  561.  
  562.     /* Blank mouse in case OFF_SPRITE or DMA off didn't work (case of PICASSO II board) */
  563.     TurnMouseOff();
  564. }
  565.  
  566. void
  567. UnBlankScreen ()
  568. {
  569.     if (screenblank == SB_DMA)
  570.     {
  571.         /* Turn DMA on */
  572.         custom.dmacon = BITSET|DMAF_RASTER|DMAF_COPPER|DMAF_SPRITE;
  573.     }
  574.     else
  575.     {
  576.         if (blankscr)
  577.             CloseScreen (blankscr);
  578.         blankscr = NULL;
  579.         ON_SPRITE;
  580.     }
  581.     blanked = FALSE;
  582.  
  583.     /* UnBlank mouse in case ON_SPRITE or DMA on didn't work (case of PICASSO II board) */
  584.     TurnMouseOn();
  585. }
  586.  
  587. #define ALL_BUTTONS     (IEQUALIFIER_LEFTBUTTON|IEQUALIFIER_RBUTTON|IEQUALIFIER_MIDBUTTON)
  588. #define KEY_QUAL        (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT \
  589.                         |IEQUALIFIER_CONTROL \
  590.                         |IEQUALIFIER_LALT|IEQUALIFIER_RALT \
  591.                         |IEQUALIFIER_LCOMMAND|IEQUALIFIER_RCOMMAND)
  592. #define ALL_QUALS       (ALL_BUTTONS|KEY_QUAL)
  593.  
  594.  
  595. /*
  596.  * MainHandler is an input handler with no filter attached, it sees everything
  597.  * and so can manage keyactivation, autopointing, keyclicking and blanking
  598.  */
  599.  
  600.  
  601. SAVEDS void
  602. MainHandler (CxMsg * CxMsg, CxObj * CO)
  603. {
  604.     static WORD apcount;        /* timer events since last mousemove */
  605.     struct InputEvent *ev;
  606.              
  607.     ev = (struct InputEvent *) CxMsgData (CxMsg);
  608.     
  609.     switch (ev->ie_Class)
  610.     {
  611.       case IECLASS_TIMER:       /*** AUTO-ACTIVATE/POP, SCREENBLANK, MOUSEBLANK ***/
  612.  
  613.         if (!(ev->ie_Qualifier & ALL_QUALS) && autopoint && !apcount--)
  614.         {
  615.             ActivateMouseWindow (AUTO);
  616.         }
  617.                 
  618.         if (screenblank && !--blankcount) /* blank screen? */
  619.         {
  620.             /* Don't blank screen while we are still in the input.device processing */
  621.             /* Take care of screen mode promotors that open requesters */
  622.             Signal (YakTask, blankscreensigflag);
  623.             blankcount = blanktimeout; /* reset counter */
  624.         }                       /* in case screen opens on top */
  625.                 
  626.         if (mouseblank && !--mblankcount) /* blank mouse? */
  627.         {
  628.             mouseoff = FALSE;   /* force reblank */
  629.             TurnMouseOff ();
  630.             /* in case someone else turns it on, reset counter */
  631.             mblankcount = REBLANKCOUNT;
  632.         }
  633.         break;
  634.  
  635.       case IECLASS_RAWKEY:
  636.         if (!(ev->ie_Code & IECODE_UP_PREFIX))
  637.         {
  638.             /*** MOUSEBLANK, KEYACTIVATE, KEYCLICK ***/
  639.                         
  640.             blankcount = blanktimeout; /* reset blanking countdown */
  641.             if (blanked)        /* turn off screen-blanking */
  642.                 UnBlankScreen ();
  643.                         
  644.             if (mouseblank)
  645.             {
  646.                 if (ev->ie_Qualifier & (IEQUALIFIER_LCOMMAND | IEQUALIFIER_RCOMMAND))
  647.                 {
  648.                     /* this allows use of keyboard to move mouse and to access menus */
  649.                     mblankcount = mblanktimeout;
  650.                     TurnMouseOn ();
  651.                 }
  652.                 else
  653.                 {
  654.                     if (blankmouseonkey)
  655.                     {
  656.                         TurnMouseOff (); /* blank the mouse */
  657.                     }
  658.                 }
  659.             }
  660.             if (click_volume && !(ev->ie_Qualifier & IEQUALIFIER_REPEAT))
  661.                 Signal (YakTask, clicksigflag);
  662.                         
  663.             if (!(ev->ie_Qualifier & ALL_BUTTONS) && keyactivate) /* perform key-activate */
  664.                 ActivateMouseWindow (KEY);
  665.  
  666.             if ( (ev->ie_Qualifier & (IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)) &&
  667.                 (ev->ie_Qualifier & IEQUALIFIER_CAPSLOCK) &&
  668.                 capshift )
  669.                 CapShiftFunction(ev);
  670.         }
  671.         break;
  672.  
  673.       case IECLASS_RAWMOUSE:
  674.         /* restore screen/mouse pointer */
  675.         blankcount = blanktimeout; /* reset blanking countdowns */
  676.         mblankcount = mblanktimeout;
  677.  
  678.         if (blanked)            /* turn off screen-blanking */
  679.             UnBlankScreen ();
  680.         if (mouseoff)
  681.             TurnMouseOn ();     /* not needed for MB_COPPER */
  682.                         
  683.         /* maybe should check for depth gadgets? nah... */
  684.         if (!(ev->ie_Qualifier & KEY_QUAL))
  685.         {
  686.             if (!(ev->ie_Qualifier & ALL_BUTTONS))
  687.             {
  688.                 apcount = autopoint_delay; /* reset auto-activate count */
  689.             }
  690.             else
  691.             {
  692.                 misspop = TRUE;
  693.                 apcount = -1;   /* button - wait for move */
  694.  
  695.                 if ((rmbactivate && (ev->ie_Code == IECODE_RBUTTON)) || 
  696.                     (mmbactivate && (ev->ie_Code == IECODE_MBUTTON)))
  697.                 {
  698.                     ActivateMouseWindow (RMBACT);
  699.                 }
  700.  
  701.                 if (ev->ie_Code == IECODE_LBUTTON)
  702.                 {
  703.                     struct Window *win = WindowUnderMouse();
  704.                     if (win == NULL)
  705.                     {
  706.                         /* Check for screen depth gadget */
  707.  
  708.                         struct Screen *screen = ScreenUnderMouse();
  709.                         struct Gadget *ScreenGadget = screen->FirstGadget;
  710.                         struct Gadget *DepthGadget = NULL;
  711.  
  712.                         while (ScreenGadget != NULL)
  713.                         {
  714.                             if ((ScreenGadget->GadgetType & GTYP_SYSTYPEMASK) == GTYP_SDEPTH)
  715.                             {
  716.                                 /* We found the screen depth gadget */
  717.                                 DepthGadget = ScreenGadget;
  718.                             }
  719.                             ScreenGadget = ScreenGadget->NextGadget;
  720.                         }
  721.         
  722.                         if ((DepthGadget != NULL) &&
  723.                             (screen->MouseY < DepthGadget->Height) &&
  724.                             (screen->MouseX > (screen->Width - DepthGadget->Width)))
  725.                         {
  726.                             /* Discard event, we'll do the processing ourselves */
  727.                             ev->ie_Class = IECLASS_NULL;
  728.  
  729.                             /* Call main task to process it */
  730.                             Signal (YakTask, depthscreensigflag);
  731.                         }
  732.                     }
  733.                     else
  734.                     {
  735.                         /* A new window will get activated, so remember it 
  736.                          * only if it is a non backdrop window
  737.                          */
  738.                         if (!(win->Flags & WFLG_BACKDROP))
  739.                         {
  740.                             RememberActiveWindow(win);
  741.                         }
  742.                     }
  743.                 }
  744.             }
  745.                         
  746.         }
  747.         break;
  748.  
  749.       case IECLASS_DISKINSERTED:
  750.         blankcount = blanktimeout; /* reset blanking countdown */
  751.         if (blanked)            /* turn off screen-blanking */
  752.             UnBlankScreen ();
  753.         break;
  754.  
  755.     }
  756. }
  757.  
  758.  
  759.  
  760. IMPORT ULONG secs, micros;
  761. IMPORT UBYTE FRONT_DELAY, BACK_DELAY;
  762.  
  763. void
  764. WindowToFrontHandler (void)
  765. {
  766.     struct Window *win; 
  767.     static ULONG lastfrontmicros = 0l;
  768.     static ULONG lastfrontsecs = 0l;
  769.     static UBYTE frontclicks = 0;
  770.  
  771.     if (Window_To_Front.RequiredClicks >1)
  772.     {
  773.         if (DoubleClick(lastfrontsecs, lastfrontmicros, secs, micros))
  774.         {
  775.             frontclicks++;
  776.         }
  777.         else
  778.         {
  779.             frontclicks = 1;
  780.         }
  781.         lastfrontmicros = micros;
  782.         lastfrontsecs =  secs;
  783.     }
  784.     else
  785.     {
  786.         frontclicks = 1;
  787.     }
  788.  
  789.     if (frontclicks == Window_To_Front.RequiredClicks) 
  790.     {
  791.         if (win = WindowUnderMouse())
  792.         { 
  793.            mousescr = win->WScreen;
  794.  
  795.             if (IsIncludedScreen (mousescr, Window_To_Front))
  796.             {
  797.                 if (OkayToPop (win) && 
  798.                     (!(Window_To_Front.Options & Opt_ExcludeWbWindow) || IsNotWbWindow (win)))
  799.  
  800.                 {
  801.                                         if (win->Flags & WFLG_WBENCHWINDOW)
  802.                                         { 
  803.                                                 /* Let some time for wb processing, otherwise 
  804.                                                  * there will be a big delay of 1 second or so
  805.                                                  */
  806.                                                 Delay(FRONT_DELAY); 
  807.                                         }
  808.                     WindowToFront (win); 
  809.                 }
  810.                 else 
  811.                 {
  812.                     if (Window_To_Front.Options & Opt_ScreenToFront)
  813.                     {   
  814.                                                 ScreenToFront (mousescr);
  815.                                                 ActivateMouseWindow (SCREEN);
  816.                      }
  817.                 }
  818.             }
  819.         }
  820.         else 
  821.         {
  822.             mousescr = ScreenUnderMouse();
  823.             if ((IsIncludedScreen ( mousescr, Window_To_Front )) && 
  824.                 (Window_To_Front.Options & Opt_ScreenToFront))
  825.             {
  826.                 MyScreenToFront(mousescr);
  827.             }
  828.         }
  829.  
  830.         frontclicks = 0;
  831.     }
  832. }
  833.  
  834.  
  835. void
  836. WindowToBackHandler (void)
  837. {
  838.     struct Window *win; 
  839.     static ULONG lastbackmicros = 0l;
  840.     static ULONG lastbacksecs = 0l;
  841.     static UBYTE backclicks = 0;
  842.  
  843.     if (Window_To_Back.RequiredClicks >1)
  844.     {
  845.         if (DoubleClick(lastbacksecs, lastbackmicros, secs, micros))
  846.         {
  847.             backclicks++;
  848.         }
  849.         else
  850.         {
  851.             backclicks = 1;
  852.         }
  853.         lastbackmicros = micros;
  854.         lastbacksecs =  secs;
  855.     }
  856.     else
  857.     {
  858.         backclicks = 1;
  859.     }
  860.  
  861.     if (backclicks == Window_To_Back.RequiredClicks) 
  862.     {
  863.         if (win = WindowUnderMouse())
  864.         {
  865.             mousescr = win->WScreen;
  866.             if (IsIncludedScreen ( mousescr, Window_To_Back ))
  867.             {
  868.                 if (!(win->Flags & WFLG_BACKDROP) && 
  869.                     (win->NextWindow || (win->WScreen->FirstWindow != win)))
  870.                 {
  871.                                         if (win->Flags & WFLG_WBENCHWINDOW)
  872.                                         { 
  873.                                                 /* Let some time for wb processing, otherwise 
  874.                                                  * there will be a big delay of 1 second or so
  875.                                                  */
  876.                                                 Delay(BACK_DELAY); 
  877.                                         }
  878.                     WindowToBack(win); 
  879.                 }
  880.                 else 
  881.                 {
  882.                     if (Window_To_Back.Options & Opt_ScreenToBack)
  883.                     {
  884.                                                 ScreenToBack (mousescr);
  885.                                                 ActivateMouseWindow (SCREEN);
  886.                     }
  887.                 }
  888.             }       
  889.         }
  890.         else 
  891.         {
  892.             mousescr = ScreenUnderMouse();
  893.             if ((IsIncludedScreen ( mousescr, Window_To_Back )) &&
  894.                 (Window_To_Back.Options & Opt_ScreenToBack))
  895.             {
  896.                 MyScreenToBack(mousescr);
  897.             }
  898.         }
  899.         backclicks = 0;
  900.     }
  901. }
  902.  
  903. void
  904. ScreenCyclingHandler (void)
  905. {
  906.     static ULONG lastcyclingmicros = 0l;
  907.     static ULONG lastcyclingsecs = 0l;
  908.     static UBYTE cyclingclicks = 0;
  909.  
  910.     if (ScreenCycling.RequiredClicks >1)
  911.     {
  912.         if (DoubleClick(lastcyclingsecs, lastcyclingmicros, secs, micros))
  913.         {
  914.             cyclingclicks++;
  915.         }
  916.         else
  917.         {
  918.             cyclingclicks = 1;
  919.         }
  920.         lastcyclingmicros = micros;
  921.         lastcyclingsecs =  secs;
  922.     }
  923.     else
  924.     {
  925.         cyclingclicks = 1;
  926.     }
  927.  
  928.     if (cyclingclicks == ScreenCycling.RequiredClicks) 
  929.     {
  930.         mousescr = ScreenUnderMouse();
  931.         if (IsIncludedScreen ( mousescr, ScreenCycling ))
  932.         {
  933.             /* ev->ie_Class = IECLASS_NULL; */
  934.             MyScreenToBack (mousescr);
  935.         }
  936.         cyclingclicks = 0;
  937.     }
  938. }
  939.  
  940.  
  941.  
  942. /* close resources allocated for MainHandler */
  943. void
  944. EndMainHandler ()
  945. {
  946.     /* DeleteCxObjAll works even with CxObj is NULL */
  947.  
  948.     DeleteCxObjAll(clickobj);    
  949.  
  950.     FreeAudio ();
  951.     if (intuiopsigbit != -1)
  952.         FreeSignal (intuiopsigbit);
  953.     if (clicksigbit != -1)
  954.         FreeSignal (clicksigbit);
  955.     if (depthscreensigbit != -1)
  956.         FreeSignal (depthscreensigbit);
  957.     if (blankscreensigbit != -1)
  958.         FreeSignal (blankscreensigbit);
  959.     UnBlankScreen ();
  960. }
  961.  
  962.  
  963. /* open resources needed for MainHandler */
  964. BOOL
  965. InitMainHandler ()
  966. {
  967.     if (((clicksigbit = AllocSignal (-1)) != -1) &&
  968.         ((intuiopsigbit = AllocSignal (-1)) != -1) &&
  969.         ((blankscreensigbit = AllocSignal (-1)) != -1) &&
  970.         ((depthscreensigbit = AllocSignal (-1)) != -1) &&
  971.         AllocAudio ())
  972.     {
  973.         YakTask = FindTask(NULL);
  974.  
  975.         clicksigflag       = 1 << clicksigbit;
  976.         intuiopsigflag     = 1 << intuiopsigbit;
  977.         blankscreensigflag = 1 << blankscreensigbit;
  978.         depthscreensigflag = 1 << depthscreensigbit;
  979.  
  980.         clickobj = CxCustom (MainHandler, 0L);
  981.         AttachCxObj (broker, clickobj);
  982.         
  983.         return TRUE;
  984.     }
  985.     EndMainHandler ();
  986.     return FALSE;
  987. }
  988.  
  989.  
  990. #endif
  991.  
  992.  
  993. #if !defined(CONV)
  994.  
  995. /* open/close resources needed for one of the MouseCycling handlers */
  996.  
  997. static VOID
  998. ToggleYakHandler (YakHandler *YH)
  999. {
  1000.     static IX tmpIX = {IX_VERSION,0, 0, 0, 0, 0, 0 }; /* declaring it as static saves some
  1001.                                                        * bytes for the intitalization code 
  1002.                                                        */
  1003.  
  1004.     /* DeleteCxObjAll() works even with NULL argument */
  1005.     DeleteCxObjAll(YH->CxObj);    
  1006.     YH->CxObj=NULL;
  1007.         
  1008.     if (YH->State == YKHK_ACTIVE) 
  1009.     {
  1010. #ifdef PREFS
  1011.         if ((YH->CxObj = CxFilter(NULL)) && !CompatibleParseIX(YH->KeyDef, &tmpIX))
  1012.         {
  1013.             /* For prefs we don't want to really set up a filter */
  1014.             DeleteCxObj(YH->CxObj); 
  1015.             YH->CxObj=NULL;
  1016.         }
  1017.         else 
  1018.             PostError("%s:\n\"%s\"", getString(Invalid_hotkey_specif_ERR), YH->KeyDef);
  1019. #else
  1020.         if ((YH->CxObj = CxFilter(NULL)) && !CompatibleParseIX(YH->KeyDef, &tmpIX))
  1021.         {
  1022.             CxObj *tmp_obj;
  1023.  
  1024.             SetFilterIX(YH->CxObj, &tmpIX);
  1025.             AttachCxObj(broker, YH->CxObj);
  1026.         
  1027.             if (tmp_obj = CxSender(broker_mp, YH->Event))
  1028.             {
  1029.                 AttachCxObj(YH->CxObj, tmp_obj);
  1030.                 if ((tmp_obj=CxTranslate(NULL)) && (tmpIX.ix_Code == IECODE_RBUTTON))
  1031.                     AttachCxObj(YH->CxObj, tmp_obj);
  1032.             }
  1033.         }
  1034. #endif
  1035.     }
  1036. }
  1037.  
  1038.  
  1039. /* open/close resources needed for Mouse Cycling */
  1040. VOID
  1041. ToggleMouseCycling(VOID)
  1042.     UBYTE i;
  1043.  
  1044.     InitMouseCyclingPatterns();
  1045.  
  1046.     for (i=0; i< NUM_HANDLERS ; i++)
  1047.     {
  1048.         ToggleYakHandler(&MouseCyclingHandlers[i]);
  1049.     }
  1050. }
  1051.  
  1052.  
  1053. #endif
  1054.